#include"interface.h"

gboolean CallBackOK(GtkWidget *Bouton, GtkWidget **Entries)
{
    printf("Nom     : %s\n", gtk_entry_get_text(GTK_ENTRY(Entries[0])));
    printf("Mot de passe : %s\n", gtk_entry_get_text(GTK_ENTRY(Entries[1])));
    return TRUE;
}

gboolean FinDialogue(GtkWidget *Dialogue, GtkWidget **Entries)
{
    g_free(Entries);
    gtk_exit(0);
    return FALSE;
}
void OnDestroy(GtkWidget * pWidget, gpointer pData)
{
    gtk_main_quit();
}

void afficheAuthentif()
{
    GtkWidget *Fenetre;
    GtkWidget *Bouton[2];
    GtkWidget **Entries;
    GtkWidget *Entry;
    GtkWidget *Table;
    GtkWidget *Label;
    GtkWidget *Logo;

    /* Parametres de la fenetre */
    Fenetre = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(Fenetre),320,517);
    gtk_window_set_position(GTK_WINDOW(Fenetre), GTK_WIN_POS_CENTER);
    gtk_window_set_title(GTK_WINDOW(Fenetre), "Chat - Authentification");

    /* Parametres de la table */
    Table=gtk_table_new(4,2,TRUE);
    gtk_container_add(GTK_CONTAINER(Fenetre), GTK_WIDGET(Table));

    /* Parametres des boutons */
    Bouton[0] = gtk_button_new_with_mnemonic("_Connecter");
    Bouton[1] = gtk_button_new_with_mnemonic("_Quitter");

    gtk_table_attach(GTK_TABLE(Table), Bouton[0], 0, 1, 3, 4, GTK_EXPAND, GTK_EXPAND , 0, 0);
    gtk_table_attach(GTK_TABLE(Table), Bouton[1], 1, 2, 3, 4, GTK_EXPAND, GTK_EXPAND , 0, 0);

    /* Parametres saisies de texte */
    Entries = g_malloc(2*sizeof(GtkWidget *));

    Label = gtk_label_new(" Nom :  ");
    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,1,2);

    Entry = gtk_entry_new();
    Entries[0]=Entry;
    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,1,2);

    Label = gtk_label_new(" Mot de passe :  ");
    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,2,3);

    Entry = gtk_entry_new_with_max_length(8);
    Entries[1]=Entry;
    gtk_entry_set_visibility(GTK_ENTRY(Entry),FALSE);
    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,2,3);

    /*g_signal_connect(G_OBJECT(Bouton[0]), "clicked",G_CALLBACK(),NULL); */
    g_signal_connect(G_OBJECT(Bouton[1]), "clicked", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(G_OBJECT(Fenetre),"destroy",G_CALLBACK(gtk_main_quit),NULL);

    /* Parametres du logo */

    Logo = gtk_image_new_from_file("img/chat1.png");
    gtk_table_attach_defaults(GTK_TABLE(Table), Logo,0,2,0,1);
    /* Parametres des entrées */
/*Entries = g_malloc(2*sizeof(GtkWidget *));
    Table= gtk_table_new(2,2,TRUE);
//    Label = gtk_label_new(" Nom :  ");
//    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,0,1);
//
//    Entry = gtk_entry_new();
//    Entries[0]=Entry;
//    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,0,1);
//
//    Label = gtk_label_new(" Mot de passe :  ");
//    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,1,2);
//
//    Entry = gtk_entry_new_with_max_length(8);
//    Entries[1]=Entry;
//    gtk_entry_set_visibility(GTK_ENTRY(Entry),FALSE);
//    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,1,2);
//
//    Bouton=gtk_button_new_with_label("OK");
//    gtk_signal_connect(GTK_OBJECT(Bouton),"Clicked", (GtkSignalFunc)CallBackOK,(gpointer)Entries);
//    gtk_signal_connect_object(GTK_OBJECT(Bouton),"Clicked",(GtkSignalFunc)gtk_widget_destroy,GTK_OBJECT(Fenetre));
//    GTK_WIDGET_SET_FLAGS(Bouton, GTK_CAN_DEFAULT);
//    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Fenetre)->action_area),Bouton,TRUE,TRUE,0);
//
//    Bouton=gtk_button_new_with_label("Quitter");
//    gtk_signal_connect_object(GTK_OBJECT(Bouton),"Clicked",(GtkSignalFunc)gtk_widget_destroy,GTK_OBJECT(Fenetre));
//    GTK_WIDGET_SET_FLAGS(Bouton, GTK_CAN_DEFAULT);
//    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Fenetre)->action_area),Bouton,TRUE,TRUE,0);*/
    gtk_widget_show_all(Fenetre);

}
void entry_callback()
{
    gtk_exit(0);
}

void afficheFenetreChat()
{
    GtkWidget *Fenetre;
    GtkWidget *Bouton;
    GtkWidget *Table;
    GtkWidget *Texte;
    GtkWidget *Entry;
    GtkWidget *Entries;

    /* Parametres de la table */
    Fenetre = gtk_dialog_new();
    gtk_window_set_default_size(GTK_WINDOW(Fenetre),720,444);
    gtk_window_set_position(GTK_WINDOW(Fenetre), GTK_WIN_POS_CENTER);
    gtk_window_set_title(GTK_WINDOW(Fenetre), "Chat - Discussion");

 /* Parametres de la table 
//    Table= gtk_table_new(2,1,TRUE);
//    gtk_container_add (GTK_CONTAINER (Fenetre), Table);*/

    /* Parametres du gtkText */
    Texte = gtk_text_new(NULL,NULL);
    gtk_text_set_editable((Texte), FALSE);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Fenetre)->vbox), Texte,TRUE,TRUE,7);

     /* Parametres du champ de saisie */
    Entry = gtk_entry_new();
    Entries=Entry;
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Fenetre)->vbox), Entry,FALSE,TRUE,7);
    g_signal_connect (Entry, "activate", G_CALLBACK(entry_callback), NULL);
/*   Label = gtk_label_new(" Mot de passe :  ");
//    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,1,2);
//
//    Entry = gtk_entry_new_with_max_length(8);
//    Entries[1]=Entry;
//    gtk_entry_set_visibility(GTK_ENTRY(Entry),FALSE);
//    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,1,2);

//    Bouton=gtk_button_new_with_label("OK");
//    gtk_signal_connect(GTK_OBJECT(Bouton),"Clicked", (GtkSignalFunc)CallBackOK,(gpointer)Entries);
//    gtk_signal_connect_object(GTK_OBJECT(Bouton),"Clicked",(GtkSignalFunc)gtk_widget_destroy,GTK_OBJECT(Dialogue));
//    GTK_WIDGET_SET_FLAGS(Bouton, GTK_CAN_DEFAULT);
//    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)->action_area),Bouton,TRUE,TRUE,0);
//
//    Bouton=gtk_button_new_with_label("Quitter");
//    gtk_signal_connect_object(GTK_OBJECT(Bouton),"Clicked",(GtkSignalFunc)gtk_widget_destroy,GTK_OBJECT(Dialogue));
//    GTK_WIDGET_SET_FLAGS(Bouton, GTK_CAN_DEFAULT);
//    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)->action_area),Bouton,TRUE,TRUE,0);
//    gtk_widget_show (Bouton);
//
//    gtk_widget_show (Table);*/
    gtk_widget_show_all(Fenetre);

}


void afficheInscription()
{
    GtkWidget *Dialogue;
    GtkWidget *Bouton;
    GtkWidget *Table;
    GtkWidget *Label;
    GtkWidget *Entry;
    GtkWidget **Entries;


    Entries = g_malloc(2*sizeof(GtkWidget *));

    Dialogue = gtk_dialog_new();


    gtk_window_set_default_size(GTK_WINDOW(Dialogue),320,517);
    gtk_window_set_position(GTK_WINDOW(Dialogue), GTK_WIN_POS_CENTER);
    gtk_window_set_title(GTK_WINDOW(Dialogue), "Chat - Inscription");

    gtk_signal_connect(GTK_OBJECT(Dialogue), "delete_event",(GtkSignalFunc)FinDialogue,(gpointer)Entries);
    gtk_signal_connect(GTK_OBJECT(Dialogue), "destroy",(GtkSignalFunc)FinDialogue,(gpointer)Entries);

    Table= gtk_table_new(4,2,TRUE);
    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(Dialogue)->vbox), Table);
    /* Champ adresse mail */
    Label = gtk_label_new(" Adresse mail :  ");
    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,0,1);

    Entry = gtk_entry_new();
    Entries[0]=Entry;
    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,0,1);

    /* Champ nom */
    Label = gtk_label_new(" Nom :  ");
    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,1,2);

    Entry = gtk_entry_new();
    Entries[1]=Entry;
    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,1,2);

    /* Champ prénom */
    Label = gtk_label_new(" prénom :  ");
    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,2,3);

    Entry = gtk_entry_new();
    Entries[2]=Entry;
    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,2,3);

    Label = gtk_label_new(" Mot de passe :  ");
    gtk_table_attach_defaults(GTK_TABLE(Table), Label,0,1,3,4);

    Entry = gtk_entry_new_with_max_length(8);
    Entries[3]=Entry;
    gtk_entry_set_visibility(GTK_ENTRY(Entry),FALSE);
    gtk_table_attach_defaults(GTK_TABLE(Table), Entry,1,2,3,4);

    Bouton=gtk_button_new_with_label("OK");
    /*gtk_signal_connect(GTK_OBJECT(Bouton),"Clicked", (GtkSignalFunc)CallBackOK,(gpointer)Entries);*/
    gtk_signal_connect_object(GTK_OBJECT(Bouton),"Clicked",(GtkSignalFunc)gtk_widget_destroy,GTK_OBJECT(Dialogue));
    GTK_WIDGET_SET_FLAGS(Bouton, GTK_CAN_DEFAULT);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)->action_area),Bouton,TRUE,TRUE,0);

    Bouton=gtk_button_new_with_label("Quitter");
    g_signal_connect(G_OBJECT(Bouton), "clicked", G_CALLBACK(gtk_main_quit), NULL);
    GTK_WIDGET_SET_FLAGS(Bouton, GTK_CAN_DEFAULT);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)->action_area),Bouton,TRUE,TRUE,0);
    gtk_widget_show_all(Dialogue);
}
/*
void main(int argc, char *argv[])
{
    gtk_init(&argc,&argv);
  afficheInscription();*/
   /* afficheAuthentif1();*/
/*   afficheFenetreChat();*/
/*    gtk_main();
}
*/
